
package org.ethereum.net.dpos;

import org.ethereum.net.message.Message;

public abstract class DPOSMessage extends Message {

	public static enum ResponseCode {
		SUCCESS(1), 
		PACKAGE_VERIFY_FAILURE(41), PACKAGE_VERIFY_FAILURE1(42), PACKAGE_FAILURE(43), PACKAGE_NOTSYNC(44), PACKAGE_EMPTY(45),
		VOTE_VERIFY_FAILURE(51), VOTE_FAILURE(52), VOTED_BROADCAST_FAILURE(53);
		// NOTICE: please DON'T set a number greater then 128, otherwise, the codec will not function!
		
		private final int code;
		private ResponseCode(int code) {
			this.code = code;
		} 
		
		public int getCode() {
			return code;
		}
		
		public static ResponseCode code(int code) {
			if (code == SUCCESS.code) {
				return SUCCESS;
			} else if (code == PACKAGE_VERIFY_FAILURE.code) {
				return PACKAGE_VERIFY_FAILURE;
			} else if (code == PACKAGE_VERIFY_FAILURE1.code) {
				return PACKAGE_VERIFY_FAILURE1;
			} else if (code == PACKAGE_NOTSYNC.code) {
				return PACKAGE_NOTSYNC;
			} else if (code == PACKAGE_FAILURE.code) {
				return PACKAGE_FAILURE;
			} else if (code == VOTE_VERIFY_FAILURE.code) {
				return VOTE_VERIFY_FAILURE;
			} else if (code == VOTE_FAILURE.code) {
				return VOTE_FAILURE;
			} else if (code == VOTED_BROADCAST_FAILURE.code) {
				return VOTED_BROADCAST_FAILURE;
			} else if (code == PACKAGE_EMPTY.code) {
				return PACKAGE_EMPTY;
			}
			throw new IllegalArgumentException("Unsupported code: " + code);
		}
	}
	
	protected ResponseCode responseCode = ResponseCode.SUCCESS;
	
    public DPOSMessage() {
    }

    public DPOSMessage(byte[] encoded) {
        super(encoded);
    }

    abstract public DPOSMessageCodes getCommand();
    
    public ResponseCode getResponseCode() {
    		return responseCode;
    }
    
//    public void setResponseCode(ResponseCode code) {
//    		this.responseCode = code;
//    }
}
